package com.neusoft.elmboot.mapper;

import java.util.List;

import com.neusoft.elmboot.dto.CartDTO;
import org.apache.ibatis.annotations.*;

import com.neusoft.elmboot.po.Cart;
import org.springframework.web.bind.annotation.DeleteMapping;

@Mapper
public interface CartMapper {

	public List<Cart> listCart(Cart cart);
	
	@Insert("insert into cart(userId,businessId,foodId,quantity) values(#{userId},#{businessId},#{foodId},1)")
	public int saveCart(Cart cart);

	//这里的quantity只能传入1或者-1
	@Update("update cart set quantity=#{quantity} where foodId=#{foodId} and businessId=#{businessId} and userId=#{userId}")
	public int updateCart(Cart cart);

	public int removeCart(Cart cart);

	@Delete("delete from cart where userId=#{userId} and businessId=#{businessId}")
	public int clearCart(CartDTO cart);

	@Select("select * from cart where userId=#{userId} and foodId=#{foodId} and businessId=#{businessId}")
	public Cart getCartByUserIdAndFoodIdAndBusinessId(Cart cart);
}
